import { Component, OnInit } from '@angular/core'
import {DictService} from "@shared/utils/dict.service";
import {DictPipe} from "@shared/pipes/dict.pipe";
import {ApiService} from "../../services/api.service";
import {CursorService} from "@core/http/cursor.service";

@Component({
  selector: 'app-tag-create-product',
  templateUrl: './tag-create-product.component.html',
  styleUrls: ['./tag-create-product.component.scss']
})
export class TagCreateProductComponent implements OnInit {
  tagname =''//标签名称
  tagtype =''//标签类型
  tagexplain =''//标签说明
  calogTag =[];//标签目录列表
  catalogcode = ''//目录名称
  scene = ''//应用场景
  tagcode  =''
  constructor( public dictService: DictService,
               private apiService: ApiService,
               public cursorService: CursorService) {}

  ngOnInit() {
    console.log('tag_type:'+ this.dictService.getDict('tag_type'))
    this.getTagCatalog();
  }
  //获取标签目录
  public getTagCatalog(){
    this.cursorService.limit = 10000;
    this.apiService.getTagCatalog(this.cursorService).subscribe(list => {
      for(let item of list){
        if(item['pcode']){
          this.calogTag.push({paramLabel:item['catalogname'],paramValue:item['catalogcode']})
        }
      }
    })
  }
  submit() {
    let data = {'manageAtrr':{}}
    if(this.catalogcode!=''){
      data['manageAtrr']['catalogcode'] =this.catalogcode
    }
    if(this.tagname!=''){
      data['manageAtrr']['tagname'] =this.tagname
    }
    if(this.tagtype!=''){
      data['manageAtrr']['tagtype'] =this.tagtype
    }
    if(this.tagexplain!=''){
      data['manageAtrr']['tagexplain'] =this.tagexplain
    }
    if(this.scene!=''){
      data['manageAtrr']['scene'] =this.scene
    }
    if(this.tagcode!=''){
      data['manageAtrr']['tagcode'] =this.tagcode
    }
    // return true
    return data
  }
}
